package com.gs.weather.controller;

import com.gs.weather.entity.DisasterInfo;
import com.gs.weather.entity.DisasterProcess;
import com.gs.weather.service.DisasterInfoService;
import com.gs.weather.service.DisasterProcessService;
import com.gs.weather.service.XsAreaService;
import com.gs.weather.vo.PageBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Legolas
 * Date: 2017/9/27 0027
 */
@Controller
@RequestMapping(value = "process")
public class DisasterProcessController {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    XsAreaService areaService;
    @Autowired
    DisasterProcessService processService;
    @Autowired
    DisasterInfoService infoService;

    //获取所有街镇名
    @RequestMapping(value = "getAreaName")
    @ResponseBody
    public List<String> getAreaNames() {
        return areaService.getXsAreaName();
    }

    //添加灾情过程
    @RequestMapping(value = "addProcess",method = RequestMethod.POST)
    @ResponseBody
    public Long addProcess(@RequestBody DisasterProcess process) {
        logger.info("getProcess->{}",process);
        return  processService.addProcess(process);
    }

    //更新灾情过程
    @RequestMapping(value = "updateProcess",method = RequestMethod.POST)
    public ResponseEntity updateProcess(@RequestBody DisasterProcess process) {
        logger.info("updateProcess->{}",process);
         return processService.updateProcess(process);
    }

    //根据时间和街镇名查询灾情过程
    @RequestMapping(value = "getProcesses")
    @ResponseBody
    public PageBean getProcessByAreaNameAndTime(String name, String time, Integer pageNum) {
        logger.info("getProcessByAreaNameAndTime->{}",name+","+time+","+pageNum);
        return processService.getAllProcess(name, time, pageNum);
    }

    //根据id查看灾情过程（包含该过程的所有灾情信息）
    @RequestMapping(value = "getProcessById")
    @ResponseBody
    public DisasterProcess getProcessById(Long id) {
        return processService.getProcessById(id);
    }

    //删除灾情过程
    @RequestMapping(value = "deleteProcess")
    public ResponseEntity deleteProcess(Long id) {
        return processService.deleteProcess(id);
    }

    //添加灾情信息
    @RequestMapping(value = "addInfo",method = RequestMethod.POST)
    public ResponseEntity addInfo(@RequestBody DisasterInfo info) {
        logger.info("addInfo->{}",info);
        return infoService.addInfo(info);
    }

    //更新灾情信息
    @RequestMapping(value = "updateInfo",method = RequestMethod.POST)
    public ResponseEntity updateInfo(@RequestBody DisasterInfo info) {
        logger.info("updateInfo->{}",info);
        return infoService.updateInfo(info);
    }


    @RequestMapping(value = "getInfos")
    @ResponseBody
    public PageBean getInfoByPage(String name, String time, Integer pageNum){
        logger.info("getInfoByPage->{}","pageNum");
        return infoService.getAllInfo(name,time,pageNum);
    }

    @RequestMapping(value = "getInfoById")
    @ResponseBody
    public DisasterInfo getInfoById(Long id){
        logger.info("getInfoById->{}","");
        return infoService.getInfoById(id);
    }


    //删除灾情信息
    @RequestMapping(value = "deleteInfo")
    public ResponseEntity deleteInfo(Long id) {
        return infoService.deleteInfo(id);
    }

}
